package monster.com.cvh.adapter;

import android.graphics.Color;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.text.ParseException;
import java.util.List;

import monster.com.cvh.R;
import monster.com.cvh.bean.NewsBean;
import monster.com.cvh.util.TimeConvert;
import monster.com.cvh.util.TimeUtil;

/**
 * Created by ASUS on 2018/3/8.
 */

public class NewsAdapter extends BaseQuickAdapter<NewsBean.DataBean, BaseViewHolder> {


    public NewsAdapter(int layoutResId, @Nullable List<NewsBean.DataBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, NewsBean.DataBean item) {
        //获取当前时间戳
        long timeStamp = System.currentTimeMillis()/1000;
        try {
            String s = TimeConvert.dateToStamp(item.getPublish_time());
            long articleTime = timeStamp - Long.valueOf(s)/1000;
            String lastTime = TimeUtil.calculateTime(articleTime);
            helper.setText(R.id.tv_item_news_time, lastTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        helper.setText(R.id.item_news_collection, String.valueOf(item.getCollect_count()));
        helper.setText(R.id.item_news_descript, item.getTitle());
        helper.setText(R.id.item_news_look, String.valueOf(item.getView_count()));
        TextView tvCollection = helper.getView(R.id.item_news_collection);
        if (mContext != null){
            Glide.with(mContext).load(item.getCover_image_URL()).placeholder(R.mipmap.information_placeholderfigure).error(R.mipmap.information_placeholderfigure).into((ImageView) helper.getView(R.id.item_news_pic));
        }else {
            return;
        }

        if (item.isIs_collect()){
            helper.setImageResource(R.id.iv_item_news_collection,R.mipmap.information_like_blue);
            tvCollection.setTextColor(Color.parseColor("#3EC8D1"));
        }else {
            helper.setImageResource(R.id.iv_item_news_collection,R.mipmap.information_like);
            tvCollection.setTextColor(Color.parseColor("#888888"));
        }
    }
}
